﻿using BLL;
using DAL;
using Model;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tools;
using 纺织贸易管理系统.设置窗体;

namespace 纺织贸易管理系统.其他窗体
{
    public partial class 唛头关联 : Form
    {
        private List<string> Maitoulist = null;
        public 唛头关联()
        {
            InitializeComponent();
        }
        private void 加载唛头()
        {
            Maitoulist = Connect.dbcontext.Queryable<ReportTable>().Where(x=>x.reportStyle== "唛头模板").Select(x=>x.reportName ).ToList ();
            gridControl2.DataSource = Maitoulist ;
        }
        private void 唛头关联_Load(object sender, EventArgs e)
        {
            加载唛头();
        }

        private void 设计唛头ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (AccessBLL.CheckAccess("修改唛头"))
            {
                var fm = new 打印设置窗体();
                //fm.ShowDialog();
                new Tools.打印唛头() { copyies = fm.copyies, PrinterName = fm.printer, userful = PrintModel.Design, moban = PrintPath.唛头模板 + gridView2.GetFocusedRow().ToString (), juan = new JuanHaoTable() }.打印();
            }
            else
            {
                ShowMessageBox.ShowErrorBox (  "您没有修改唛头的权限！请让管理员给你开通");
            }
           
        }

        private void 新增ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (AccessBLL.CheckAccess("新增唛头"))
            {
                var fm = new InpuBox() { Label = "请输入你要新建的模板名称", 内容 = "",filePath=PrintPath.唛头模板  };
                fm.ShowDialog();
                if (Tools.获取模板.新增模板(PrintPath.唛头模板, fm.内容, fm.参考模板, ReportService.唛头))
                {
                    加载唛头();
                   //gridView2.GetFocusedRow() = fm.内容 + ".frx";
                    var f = new 打印设置窗体();
                    //fm.ShowDialog();
                    new Tools.打印唛头() { copyies = f.copyies, PrinterName = f.printer, userful = PrintModel.Design, moban = PrintPath.唛头模板 + fm.内容+".frx", juan = new JuanHaoTable() }.打印();
                }
            }
            else
            {
                ShowMessageBox.ShowErrorBox (  "您没有新增唛头的权限！请让管理员给你开通");
            }
        }

        private void linkSave_Click(object sender, EventArgs e)
        {
            var maitou = (gridControl2.DataSource as List<Maitou>)[gridView2.FocusedRowHandle];
            MaitouService.UpdateMaitou(maitou, x => x.khbh == maitou.khbh);
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (AccessBLL.CheckAccess("删除唛头"))
            {
                Tools.ReportService.Delete(new ReportTable { reportName = gridView2.GetFocusedRow().ToString (), reportStyle = Tools.ReportService.唛头 }, Application.StartupPath);
                加载唛头();
            }
            else
            {
                ShowMessageBox.ShowErrorBox (  "您没有删除唛头的权限！请让管理员给你开通");
            }
        }

        private void 预览唛头ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new Tools.打印唛头() { copyies = 1, userful = PrintModel.Privew, moban = PrintPath.唛头模板 + gridView2.GetFocusedRow(), juan = new JuanHaoTable() }.打印();
        }

        private void gridView2_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            new Tools.打印唛头() { copyies = 1, userful = PrintModel.Privew, moban = PrintPath.唛头模板 + gridView2.GetFocusedRow(), juan = new JuanHaoTable() }.getPrivew(PreviewControl1);
        }
    }
}
